package com.leo;

import com.jfoenix.controls.JFXTextField;
import com.jfoenix.validation.RequiredFieldValidator;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.net.URL;

/**
 * @ClassName JFXTextFieldDemo
 * @Description
 * @Author wangss
 * @date 2020.11.26 11:25
 * @Version 1.0
 */
public class JFXTextFieldDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        JFXTextField field = new JFXTextField();
        field.setLabelFloat(true);
        field.setPromptText("Floating prompt");

        JFXTextField validationField = new JFXTextField();
        validationField.setPromptText("With Validation..");
        RequiredFieldValidator validator = new RequiredFieldValidator();
        validator.setMessage("Input Required");
//        validator.setAwsomeIcon(new Icon(AwesomeIcon.WARNING,"2em",";","error"));
        validationField.getValidators().add(validator);
        validationField.focusedProperty().addListener((o, oldVal, newVal) -> {
            if (!newVal) {
                validationField.validate();
            }
        });

        AnchorPane an = new AnchorPane();
        an.getChildren().addAll(field, validationField);

        AnchorPane.setTopAnchor(field, 20.0);
        AnchorPane.setLeftAnchor(field, 20.0);

        AnchorPane.setTopAnchor(validationField, 20.0);
        AnchorPane.setLeftAnchor(validationField, 280.0);

        Scene scene = new Scene(an);
        URL url = this.getClass().getResource("/css/myStyle.css");
        scene.getStylesheets().add(url.toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setWidth(800);
        primaryStage.setHeight(650);
        primaryStage.setTitle("JFoeniX测试");
        primaryStage.show();
    }
}
